﻿using System.Reactive;
using System.Reactive.Linq;
using Console = System.Console;
using System;
using System.Linq;

namespace Event.ReactiveProgramming
{
    public class ObservableCreater
    {
        public void UsingRange()
        {
            Observable.Range(1, 10)
           .Subscribe(x => Console.WriteLine(x.ToString()));
        }

        public void UsingInterval()
        {
            Observable.Interval(TimeSpan.FromSeconds(1))
                .Subscribe(x => Console.WriteLine(x.ToString()));
        }

        public void RegisterOnErrorAndOnCompleted()
        {
            Observable.Range(1, 10)
           .Subscribe(x => Console.WriteLine(x.ToString()), e => Console.WriteLine("Error" + e.Message), () => Console.WriteLine("Completed"));
        }

        public void ChangeEnumerableToObservable()
        {
            Enumerable.Range(1, 10).ToObservable()
                .Subscribe(x => Console.WriteLine(x.ToString()));
        }

        public void ChangeObservableToEnumerable()
        {
            var list= Observable.Range(1, 10).ToEnumerable();
        }
    }
}